from universal.common_header import *
from universal.common_header_widget import *
from Module.TrainAndTest.GPU import Window_progress

class PaintArea(QWidget):
    def __init__(self):
        super(PaintArea, self).__init__()
        self.bgColor = QColor(81, 214, 255)
        self.setPalette(QPalette(self.bgColor))
        self.Shape = ["Line", "Rectangle", 'Rounded Rectangle', "Ellipse", "Pie", 'Chord',
                      "Path", "Polygon", "Polyline", "Arc", "Points", "Text", "Pixmap"]
        self.setShape('Line')
        self.setAutoFillBackground(True)
        self.setMinimumSize(100, 100)
        self.pen = QPen()
        self.brush = QBrush()
        self.GPUICPU = Window_progress()
        self.GPUICPU_labelCpu = QLabel('           CpuUsage')
        self.GPUICPU_labelCpu.setFont(QFont(FONTSTR, 11))
        self.GPUICPU_labelGpu = QLabel('           GpuUsage')
        self.GPUICPU_labelGpu.setFont(QFont(FONTSTR, 11))
        self.label1 = createLabel(self,'0 Images',self.bgColor,Qt.AlignCenter)
        self.label1.setFont(QFont(FONTSTR, 16))
        self.label2 = createLabel(self,'Date: '+time.strftime('%Y-%m-%d'),self.bgColor,Qt.AlignCenter)
        self.label2.setFont(QFont(FONTSTR, 16))
        self.label3 = createLabel(self,'章 鱼 博 士',self.bgColor,Qt.AlignCenter)
        self.label3.setFont(QFont('Imprint MT Shadow', 24, QFont.Bold))
        self.label4 = QLabel(self)
        self.label4.setGeometry(0,0,0,0)
        jpg = QPixmap("icons/analysis.png").scaled(100, 100,Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.label4.setPixmap(jpg)  # 在label上显示图片
        self.label5 = QLabel(self)
        self.label5.setGeometry(0,0,0,0)
        jpg = QPixmap("icons/train.png").scaled(100, 100,Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.label5.setPixmap(jpg)  # 在label上显示图片
        # self.label4.setMaximumSize(150,49)

        self.gridLayout = QGridLayout()
        self.gridLayout.setSpacing(0)
        self.gridLayout.addWidget(self.GPUICPU._widgets[0], 0, 0)
        self.gridLayout.addWidget(self.GPUICPU._widgets[1], 0, 1)
        self.gridLayout.addWidget(self.GPUICPU_labelCpu, 1, 1)
        self.gridLayout.addWidget(self.GPUICPU_labelGpu, 1, 0)
        self.gridLayout.addWidget(self.label5,0,3)
        self.gridLayout.addWidget(self.label1,0,2)
        self.gridLayout.addWidget(self.label2,1,2)
        self.gridLayout.addWidget(self.label3,0,4)
        self.gridLayout.addWidget(self.label4,0,5)
        self.setLayout(self.gridLayout)
        self.setFont(QFont(FONTSTR,FONT_SIZE3))

    def clsoeCpuAndGpu(self):
        self.GPUICPU.show_ration = False

    def setShape(self, s):
        self.shape = s
        self.update()

    def setPen(self, p):
        self.pen = p
        self.update()

    def setBrush(self, b):
        self.brush = b
        self.update()

    # def paintEvent(self, QPaintEvent):
    #     p = QPainter(self)
    #     p.setPen(self.pen)
    #     p.setBrush(self.brush)
    #
    #     rect = QRect(0, 150, 1480, 0)
    #
    #     points = [QPoint(150, 100), QPoint(300, 150), QPoint(350, 250), QPoint(100, 300)]
    #     startAngle = 30 * 16
    #     spanAngle = 120 * 16
    #
    #     path = QPainterPath()
    #     path.addRect(150, 150, 100, 100)
    #     path.moveTo(100, 100)
    #     path.cubicTo(300, 100, 200, 200, 300, 300)
    #     path.cubicTo(100, 300, 200, 200, 100, 100)
    #
    #     if self.shape == "Line":
    #         p.drawLine(rect.topLeft(),rect.bottomRight())
    #     elif self.shape == "Rectangle":
    #         p.drawRect(rect)
    #     elif self.shape == 'Rounded Rectangle':
    #         p.drawRoundedRect(rect, 25, 25, Qt.RelativeSize)
    #     elif self.shape == "Ellipse":
    #         p.drawEllipse(rect)
    #     elif self.shape == "Polygon":
    #         p.drawPolygon(QPolygon(points), Qt.WindingFill)
    #     elif self.shape == "Polyline":
    #         p.drawPolyline(QPolygon(points))
    #     elif self.shape == "Points":
    #         p.drawPoints(QPolygon(points))
    #     elif self.shape == "Pie":
    #         p.drawPie(rect, startAngle, spanAngle)
    #     elif self.shape == "Arc":
    #         p.drawArc(rect, startAngle, spanAngle)
    #     elif self.shape == "Chord":
    #         p.drawChord(rect, startAngle, spanAngle)
    #     elif self.shape == "Path":
    #         p.drawPath(path)
    #     elif self.shape == "Text":
    #         p.drawText(rect, Qt.AlignCenter, "Hello Qt!")
    #     elif self.shape == "Pixmap":
    #         p.drawPixmap(QPixmap("icons/1.jpg"))